<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of SortieStock
 * sortiestock
 * 
 * `datesortie` DATETIME NULL ,
    idarticle int not null,
    identrepot int not null,
    idsociete int not null,
 * @author Gael
 */
class SortieStock {
    public $id;
    public $datesortie;
    public $societe;
    public $entrepot;
    public $article;
    
    function __construct($id, $datesortie, $societe, $entrepot, $article) {
        $this->id = $id;
        $this->datesortie = $datesortie;
        $this->societe = $societe;
        $this->entrepot = $entrepot;
        $this->article = $article;
    }
    
    public function getId() {
        return $this->id;
    }

    public function setId($id) {
        $this->id = $id;
    }

    public function getDatesortie() {
        return $this->datesortie;
    }

    public function setDatesortie($datesortie) {
        $this->datesortie = $datesortie;
    }

    public function getSociete() {
        return $this->societe;
    }

    public function setSociete($societe) {
        $this->societe = $societe;
    }

    public function getEntrepot() {
        return $this->entrepot;
    }

    public function setEntrepot($entrepot) {
        $this->entrepot = $entrepot;
    }

    public function getArticle() {
        return $this->article;
    }

    public function setArticle($article) {
        $this->article = $article;
    }


     static public function byId($id){
        try{
            $db= getPdo();
            $rep = $db->query("select * from sortiestock where id=$id" );
            while($data =$rep->fetch()){
                $ta= new SortieStock($data['id'],  
                        $data['datesortie'],
                        Societe::byId($data['idsociete']),
                        Entrepot::byId($data['identrepot']),
                        Article::byId($data['idarticle']));
            }
            
            $rep->closeCursor();
            return $ta;
        }catch(Exception $e){
            die('erreur requete'.$e->getMessage());
            return false;
        }
    }
    static public function all(){
        try{
            $db= getPdo();
            $tab = array();
            
            $rep = $db->query("select * from sortiestock  " );
            while($data =$rep->fetch()){
                
                $tab[$data['id']]=new SortieStock($data['id'],  
                        $data['datesortie'],
                        Societe::byId($data['idsociete']),
                        Entrepot::byId($data['identrepot']),
                        Article::byId($data['idarticle']));
            }
            $rep->closeCursor();
            return $tab;
        }catch(Exception $e){
            die('erreur requete'.$e->getMessage());
        }
    } 
    

}

?>
